import request from '@/config/axios'

export type VideoVO = {
  id: string
  /** 视频标题 */
  videoName: string
  /** 视频封面链接 */
  videoCoverUrl: string
  /** 百家云视频id */
  bjyVideoId: string
  /** 视频时长(s) */
  videoDuration: number
  /** 视频大小(b) */
  videoSize: number
  /** 视频描述 */
  videoDesc: string
  /** 创建时间 */
  createTime: number
  /** 更新时间 */
  updateTime: number
}

export type VideoCreateDTO = Omit<VideoVO, 'id' | 'createTime' | 'updateTime'>

export type VideoUpdateDTO = Pick<VideoVO, 'id' | 'videoName'>

export type VideoPageParam = PageParam & Partial<Pick<VideoVO, 'videoName'>>

export type SearchSimplePageParam = PageParam & { videoName?: string }

export type SearchSimplePageResp = Pick<VideoVO, 'id' | 'videoName'>

const baseURL = '/train/course/video'

/** 分页获取视频列表，可根据videoName过滤 */
export const getPage = (data: VideoPageParam) =>
  request.post<PageResult<VideoVO[]>>({
    url: `${baseURL}/page-course-video`,
    data
  })

/** 简单搜索数据 */
export const pageCourseVideoSearch = (data: SearchSimplePageParam) =>
  request.post<PageResult<SearchSimplePageResp>>({
    url: `${baseURL}/page-course-video-search`,
    data
  })

/** 根据id获取视频详情 */
export const get = (id: string) =>
  request.get<VideoVO>({
    url: `${baseURL}/get-course-video-detail`,
    params: { id }
  })

/** 创建视频 */
export const create = (data: VideoCreateDTO) =>
  request.post<boolean>({
    url: `${baseURL}/create`,
    data
  })

/** 更新视频 */
export const update = (data: VideoUpdateDTO) =>
  request.post<boolean>({
    url: `${baseURL}/update`,
    data
  })

/** 根据id删除视频 */
export const deleteById = (id: string) =>
  request.post<boolean>({
    url: `${baseURL}/delete`,
    params: { id }
  })
